package com.store.controller;

import com.store.service.OrderService;
import com.store.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@Api("订单控制层")
@RestController
@RequestMapping("/order")
public class OrderController {

    @DubboReference(interfaceClass = OrderService.class,version = "1.0.0",timeout = 5000)
    private OrderService orderService;

    @ApiOperation("新增订单")
    @PostMapping("/addOrder")
    public JsonResult addOrder(Integer aid, Integer[] cids, HttpSession session){
        Integer uid = (Integer)session.getAttribute("uid");
        String username = (String)session.getAttribute("username");
        Integer oid = orderService.addOrder(uid, aid, username, cids);
        session.setAttribute("oid",oid);
        session.setAttribute("cids",cids);
        return new JsonResult(200);
    }

    @ApiOperation("更新订单信息")
    @GetMapping("/updateOrder")
    public JsonResult updateOrder(HttpSession session){
        Integer oid = (Integer) session.getAttribute("oid");
        System.out.println(oid);
        Integer[] cids = (Integer[]) session.getAttribute("cids");
        orderService.updateOrder(oid,cids);
        return new JsonResult(200);
    }
}
